using System;
using System.Collections.Generic;
using System.Linq;
using Granite.Metadata;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Granite.Commons.Tests.Metadata
{
    [TestClass]
    public class PropertyMetadataCollectionTests
    {
        [TestMethod]
        public void PropertyMetadataCollection_CopyTo_Test1()
        {
            try
            {
                var result = MetadataCache.GetMetadata(typeof(Mock)).Properties;
                result.CopyTo(null, 0);

                Assert.Fail("Expected an ArgumentNullException");
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("array", ex.ParamName, "Incorrect parameter name");
            }
        }

        [TestMethod]
        public void PropertyMetadataCollection_CopyTo_Test2()
        {
            try
            {
                var result = MetadataCache.GetMetadata(typeof(Mock)).Properties;
                var array = new PropertyMetadata[0];
                result.CopyTo(array, 0);

                Assert.Fail("Expected an ArgumentNullException");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Assert.AreEqual("arrayIndex", ex.ParamName, "Incorrect parameter name");
            }
        }

        [TestMethod]
        public void PropertyMetadataCollection_CopyTo_Test3()
        {
            var result = MetadataCache.GetMetadata(typeof(Mock)).Properties;
            var array = new PropertyMetadata[result.Count];
            result.CopyTo(array, 0);
            foreach (var p in result)
                CollectionAssert.Contains(array, p);
        }

        [TestMethod]
        public void PropertyMetadataCollection_CopyTo_Test4()
        {
            try
            {
                var result = MetadataCache.GetMetadata(typeof(Mock)).Properties;
                var array = new PropertyMetadata[0];
                result.CopyTo(array, 1);

                Assert.Fail("Expected an ArgumentNullException");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Assert.AreEqual("arrayIndex", ex.ParamName, "Incorrect parameter name");
            }
        }

        [TestMethod]
        public void PropertyMetadataCollection_CopyTo_Test5()
        {
            try
            {
                var result = MetadataCache.GetMetadata(typeof(Mock)).Properties;
                var array = new PropertyMetadata[0];
                result.CopyTo(array, -1);

                Assert.Fail("Expected an ArgumentNullException");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Assert.AreEqual("arrayIndex", ex.ParamName, "Incorrect parameter name");
            }
        }

 
    }
}
